今晚來透過Docker-compose,來建立3個節點的etcd Cluster.
方便後面使用.
網路環境拓樸圖:
version: "3.6"
services:
node1:
image: quay.io/coreos/etcd:v3.4.0
volumes:
- node1-data:/etcd-data
ports:
- "12379:2379"
expose:
- 2379
- 2380
networks:
cluster_net:
ipv4_address: 172.16.238.100
environment:
- ETCDCTL_API=3
command:
- /usr/local/bin/etcd
- --data-dir=/etcd-data
- --name=node1
- --initial-advertise-peer-urls=http://172.16.238.100:2380
- --listen-peer-urls=http://0.0.0.0:2380
- --advertise-client-urls=http://172.16.238.100:2379
- --listen-client-urls=http://0.0.0.0:2379
- --initial-cluster=node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380
- --initial-cluster-state=new
- --initial-cluster-token=docker-etcd
- --auto-compaction-retention=1
- --auto-compaction-mode=periodic
node2:
image: quay.io/coreos/etcd:v3.4.0
volumes:
- node2-data:/etcd-data
networks:
cluster_net:
ipv4_address: 172.16.238.101
environment:
- ETCDCTL_API=3
ports:
- "12380:2379"
expose:
- 2379
- 2380
command:
- /usr/local/bin/etcd
- --data-dir=/etcd-data
- --name=node2
- --initial-advertise-peer-urls=http://172.16.238.101:2380
- --listen-peer-urls=http://0.0.0.0:2380
- --advertise-client-urls=http://172.16.238.101:2379
- --listen-client-urls=http://0.0.0.0:2379
- --initial-cluster=node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380
- --initial-cluster-state=new
- --initial-cluster-token=docker-etcd
- --auto-compaction-retention=1
- --auto-compaction-mode=periodic
node3:
image: quay.io/coreos/etcd:v3.4.0
volumes:
- node3-data:/etcd-data
networks:
cluster_net:
ipv4_address: 172.16.238.102
environment:
- ETCDCTL_API=3
ports:
- "12381:2379"
expose:
- 2379
- 2380
command:
- /usr/local/bin/etcd
- --data-dir=/etcd-data
- --name=node3
- --initial-advertise-peer-urls=http://172.16.238.102:2380
- --listen-peer-urls=http://0.0.0.0:2380
- --advertise-client-urls=http://172.16.238.102:2379
- --listen-client-urls=http://0.0.0.0:2379
- --initial-cluster=node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380
- --initial-cluster-state=new
- --initial-cluster-token=docker-etcd
- --auto-compaction-retention=1
- --auto-compaction-mode=periodic
volumes:
node1-data:
node2-data:
node3-data:
networks:
cluster_net:
driver: bridge
ipam:
driver: default
config:
-
subnet: 172.16.238.0/24
etcd主要用到兩個Port2379
、2380
.2379
主要是給外部或者是client端使用的.2380
則是給etcd各節點內部調用的.
要使用etcd V3版本, 需要配置環境變數ETCDCTL_API=3
可以透過etcdctl來查證版本
data-dir
這個就用來放置WAL寫入的資料
name
顧名思義就是節點名稱, 方便管理initial-advertise-peer-urls
集群之中, 給其他內部節點對該節點調用的URL網址, 如果有多個中間用,
隔開.
預設是http://localhost:2380
舉例http://example.com:2380, http://10.0.0.1:2380
listen-peer-urls
用來告訴etcd說, 能接受來自指定scheme:IP:port的傳入請求. scheme包含了http或https.
如果IP指定成0.0.0.0則表示etcd會接聽所有來自這port的傳入請求.
如果有多個中間用,
隔開.
預設是http://localhost:2380
舉例http://10.0.0.1:2380
advertise-client-urls
給外部/client來調用的URL, 如果有多個中間用,
隔開.
預設是http://localhost:2379
listen-client-urls
跟listen-peer-urls
差別在於, 這個是給外部/client用的.
預設是http://localhost:2379
initial-cluster
就集群初始化的啟動配置, 主要配置集群一開始各節點的名稱跟 位子name=initial-advertise-peer-urls
, 如果有多個中間用,
隔開.
預設是default=http://localhost:2380
initial-cluster-state
就兩個值new
orexisting
主要就告訴etcd節點, 是全新的叢集還是嘗試去加入其他已經存在的叢集.
預設是new
initial-cluster-token
集群的名字(我覺得是這樣)
官網寫Initial cluster token for the etcd cluster during bootstrap.
預設是etcd-cluster
所有init-*
開頭的設定, 都只有在啟動集群時才會用到.
auto-compaction-retention
mvcc紀錄將會被保存多久, 0表示關閉自動壓縮.
預設是0
auto-compaction-mode
用來解釋auto-compaction-retention
, 選項有periodic
跟revision
; 如果選擇periodic, 那auto-compaction-retention的值就是保留幾小時以內的; 如果選擇revision就是保留最近幾個版本之內的.
預設是periodic